package com.demo.launcher;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.library.launcher.ActivityLauncher;
import com.library.launcher.OnActivityResultListener;

/**
 * @author : Zach
 * @desc :
 * @date : 2021/11/9 17:11
 */
public class TargetFragmentX extends Fragment {

    TextView tvText;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View convertView = inflater.inflate(R.layout.fragment_test, container, false);
        initView(convertView);
        return convertView;
    }

    private void initView(View view) {
        ((TextView) view.findViewById(R.id.tvTitle)).setText("androidx Fragment");
        tvText = view.findViewById(R.id.tvText);
        Button btn = view.findViewById(R.id.btn);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityLauncher.with(TargetFragmentX.this)
                        .targetActivity(TargetActivity.class)
                        .launch(new OnActivityResultListener() {
                            @Override
                            public void onActivityResult(int resultCode, Intent data) {
                                tvText.setText("onActivityResult:\nresultCode = " + resultCode + "\n" + data.toUri(0));
                            }
                        });
            }
        });
    }
}
